package cn.hdu.liang.generics;

import cn.hdu.liang.generics.coffee.Generator;

import java.util.ArrayList;
import java.util.Random;

class Product {
    private final int id;
    private String descr;
    private double price;

    public Product(int id, String descr, double price) {
        this.id = id;
        this.descr = descr;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", descr='" + descr + '\'' +
                ", price=" + price +
                '}';
    }

    public void priceChange(double change) {
        price += change;
    }

    public static Generator<Product> generator = new Generator<Product>() {
        private Random random = new Random(47);

        @Override
        public Product next() {
            return new Product(random.nextInt(1000), "Test", Math.round(random.nextDouble() * 1000.0) + 0.99);
        }
    };
}

class Shelf extends ArrayList<Product> {
    public Shelf(int nProducts) {
        Generators.fill(this, Product.generator, nProducts);
    }
}

class Aisle extends ArrayList<Shelf> {
    public Aisle(int nShelves, int nProducts) {
        for(int i = 0; i < nShelves; i++) {
            add(new Shelf(nProducts));
        }
    }
}

class CheckoutStand {

}

class Office {

}

public class Store extends ArrayList<Aisle> {
    private ArrayList<CheckoutStand> checkouts = new ArrayList<>();
    private Office office = new Office();
    private Shelf shelf = new Shelf(3);

    public Store(int nAisles, int nShelves, int nProducts) {
        for(int i = 0; i < nAisles; i++) {
            add(new Aisle(nShelves, nProducts));
        }
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        /*for(Aisle aisle : this) {
            for(Shelf shelf : aisle) {
                for(Product product : shelf) {
                    result.append(product);
                    result.append("\n");
                }
            }
        }*/

        this.forEach(aisle ->
                aisle.forEach(shelf ->
                        shelf.forEach(product -> {
                            result.append(product);
                            result.append("\n");
                        })));
        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Store(2, 2, 2));
    }
}
